package com.ruoyi.pims.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.pims.domain.RyPurchaseAnalysis;
import com.ruoyi.pims.service.IRyPurchaseAnalysisService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 采购分析主Controller
 * 
 * @author ruoyi
 * @date 2025-06-18
 */
@Controller
@RequestMapping("/pims/analysis")
public class RyPurchaseAnalysisController extends BaseController
{
    private String prefix = "pims/analysis";

    @Autowired
    private IRyPurchaseAnalysisService ryPurchaseAnalysisService;

    @RequiresPermissions("pims:analysis:view")
    @GetMapping()
    public String analysis()
    {
        return prefix + "/analysis";
    }

    /**
     * 查询采购分析主列表
     */
    @RequiresPermissions("pims:analysis:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(RyPurchaseAnalysis ryPurchaseAnalysis)
    {
        startPage();
        List<RyPurchaseAnalysis> list = ryPurchaseAnalysisService.selectRyPurchaseAnalysisList(ryPurchaseAnalysis);
        return getDataTable(list);
    }

    /**
     * 导出采购分析主列表
     */
    @RequiresPermissions("pims:analysis:export")
    @Log(title = "采购分析主", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(RyPurchaseAnalysis ryPurchaseAnalysis)
    {
        List<RyPurchaseAnalysis> list = ryPurchaseAnalysisService.selectRyPurchaseAnalysisList(ryPurchaseAnalysis);
        ExcelUtil<RyPurchaseAnalysis> util = new ExcelUtil<RyPurchaseAnalysis>(RyPurchaseAnalysis.class);
        return util.exportExcel(list, "采购分析主数据");
    }

    /**
     * 新增采购分析主
     */
    @RequiresPermissions("pims:analysis:add")
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存采购分析主
     */
    @RequiresPermissions("pims:analysis:add")
    @Log(title = "采购分析主", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(RyPurchaseAnalysis ryPurchaseAnalysis)
    {
        return toAjax(ryPurchaseAnalysisService.insertRyPurchaseAnalysis(ryPurchaseAnalysis));
    }

    /**
     * 修改采购分析主
     */
    @RequiresPermissions("pims:analysis:edit")
    @GetMapping("/edit/{analysisId}")
    public String edit(@PathVariable("analysisId") Long analysisId, ModelMap mmap)
    {
        RyPurchaseAnalysis ryPurchaseAnalysis = ryPurchaseAnalysisService.selectRyPurchaseAnalysisByAnalysisId(analysisId);
        mmap.put("ryPurchaseAnalysis", ryPurchaseAnalysis);
        return prefix + "/edit";
    }

    /**
     * 修改保存采购分析主
     */
    @RequiresPermissions("pims:analysis:edit")
    @Log(title = "采购分析主", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(RyPurchaseAnalysis ryPurchaseAnalysis)
    {
        return toAjax(ryPurchaseAnalysisService.updateRyPurchaseAnalysis(ryPurchaseAnalysis));
    }

    /**
     * 删除采购分析主
     */
    @RequiresPermissions("pims:analysis:remove")
    @Log(title = "采购分析主", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(ryPurchaseAnalysisService.deleteRyPurchaseAnalysisByAnalysisIds(ids));
    }
}
